package com.damacheng009.future.alarm.job;

import java.util.List;

import org.ta4j.core.BaseTimeSeries;
import org.ta4j.core.TimeSeries;
import org.ta4j.core.indicators.EMAIndicator;
import org.ta4j.core.indicators.MACDIndicator;
import org.ta4j.core.indicators.SMAIndicator;
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
import org.ta4j.core.indicators.helpers.CrossIndicator;
import org.ta4j.core.indicators.helpers.HighestValueIndicator;
import org.ta4j.core.indicators.helpers.LowestValueIndicator;
import org.ta4j.core.indicators.helpers.MaxPriceIndicator;
import org.ta4j.core.indicators.helpers.MinPriceIndicator;
import org.ta4j.core.indicators.statistics.SimpleLinearRegressionIndicator;
import org.ta4j.core.num.Num;
import org.ta4j.core.num.PrecisionNum;

import com.damacheng009.future.alarm.crawler.BaseCrawler;
import com.damacheng009.future.alarm.service.DayKLineService;
import com.damacheng009.future.alarm.toolkit.GlobalConfig;
import com.damacheng009.future.alarm.toolkit.HTMLTool;
import com.damacheng009.future.alarm.toolkit.MailTool;
import com.damacheng009.future.alarm.toolkit.MiscTool;
import com.damacheng009.future.alarm.vo.KLineVo;
import com.damacheng009.future.alarm.vo.DayKLineInfo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ExceptionUtil;

public abstract class BaseOneHourJob {
	
	protected int shortNum;
	
	protected int middleNum;
	
	protected String curCode;
	
	protected BaseCrawler crawler;
	
	protected String[] codeList;
	
	// k线数据
	protected TimeSeries series;
	
	// 收盘价指标
	protected ClosePriceIndicator closePriceIndicator;
	
	// 最高价指标
	protected MaxPriceIndicator maxPriceIndicator;
		
	// 最低价指标
	protected MinPriceIndicator minPriceIndicator;
	
	// 短期简单移动平均线指标
	protected SMAIndicator smaShortIndicator;
	
	// 中期简单移动平均线指标
	protected SMAIndicator smaMiddleIndicator;
	
	// sma下穿指标
	protected CrossIndicator smaDownCrossIndicator;
	
	// sma上穿指标
	protected CrossIndicator smaUpCrossIndicator;
	
	// 短期均线斜率指标
	protected SimpleLinearRegressionIndicator smaShortLRIndicator;
	
	// 中期斜率指标
	protected SimpleLinearRegressionIndicator smaMiddleLRIndicator;
	
	// MACD diff指标			
	protected MACDIndicator macdDiffIndicator;
	
	// MACD dea指标
	protected EMAIndicator macdDeaIndicator;
	
	// MACD下穿指标
	protected CrossIndicator macdDownCrossIndicator;
	
	// MACD上穿指标
	protected CrossIndicator macdUpCrossIndicator;
	
	protected int endIndex;
	
	// 斜率为正代表向上，为负代表向上，数值越大越陡峭，越小越平缓
	// 短周期斜率数值
	protected Num slopeShort;
	
	// 中周期斜率数值
	protected Num slopeMiddle;
	
	// 最近的收盘价
	protected Num closePrice;
	
	// 最近的最高价
	protected Num maxPrice;
	
	// 最近的最低价
	protected Num minPrice;
	
	// 短周期均线数值
	protected Num smaShortValue;
	
	// 中周期均线数值
	protected Num smaMiddleValue;
	
	// MACD diff数值
	protected Num macdDiff;
	
	// MACD dea数值
	protected Num macdDea;
	
	// macd数值
	protected Num macd;
	
	// 日线均线指标信息
	protected DayKLineInfo daySMAInfo;
	
	// 分数
	protected int score;
	
	// N个周期内最高价指标
	protected HighestValueIndicator hvi;
	
	// N个周期内最低价指标
	protected LowestValueIndicator lvi;
	
	// N个周期内最高价
	protected Num hv;
	
	// N个周期内最低价
	protected Num lv;
	
	protected void initKLines(String code) {
		List<KLineVo> klines = crawler.getKLines(code);
		
		if (klines != null) {
			// Creating a time series (from any provider: CSV, web service, etc.)
			series = new BaseTimeSeries.SeriesBuilder().withName("60min_series").build();

			for (KLineVo line : klines) {
				// 如果当前K线的结束时间跟上一跟相同则跳过
				if (!series.isEmpty() && MiscTool.changeShanghaiToUTC(line.getD()).isEqual(series.getLastBar().getEndTime())) {
					continue;
				}
				
				series.addBar(MiscTool.changeShanghaiToUTC(line.getD()), line.getO(), 
						line.getH(), line.getL(), line.getC(), line.getV());
			}
		}
	}
	
	protected void initIndicators() {
		closePriceIndicator = new ClosePriceIndicator(series);
		maxPriceIndicator = new MaxPriceIndicator(series);
		minPriceIndicator = new MinPriceIndicator(series);
		
		smaShortIndicator = new SMAIndicator(closePriceIndicator, shortNum);
		smaMiddleIndicator = new SMAIndicator(closePriceIndicator, middleNum);
		
		smaDownCrossIndicator = new CrossIndicator(smaShortIndicator, smaMiddleIndicator);
		smaUpCrossIndicator = new CrossIndicator(smaMiddleIndicator, smaShortIndicator);

		smaShortLRIndicator = 
				new SimpleLinearRegressionIndicator(smaShortIndicator, 5, SimpleLinearRegressionIndicator.SimpleLinearRegressionType.slope);
		smaMiddleLRIndicator = 
				new SimpleLinearRegressionIndicator(smaMiddleIndicator, 5, SimpleLinearRegressionIndicator.SimpleLinearRegressionType.slope);
			
		macdDiffIndicator = new MACDIndicator(closePriceIndicator, 12, 26);
		macdDeaIndicator = new EMAIndicator(macdDiffIndicator, 9);
		macdDownCrossIndicator = new CrossIndicator(macdDiffIndicator, macdDeaIndicator);
		macdUpCrossIndicator = new CrossIndicator(macdDeaIndicator, macdDiffIndicator);
	
		hvi = new HighestValueIndicator(maxPriceIndicator, GlobalConfig.ALARM_60MIN_MAXMIN_BAR_CNT);
		lvi = new LowestValueIndicator(minPriceIndicator, GlobalConfig.ALARM_60MIN_MAXMIN_BAR_CNT);
	}
	
	protected void initValues(String code) {
		endIndex = series.getEndIndex();

		slopeShort = smaShortLRIndicator.getValue(endIndex);
		slopeMiddle = smaMiddleLRIndicator.getValue(endIndex);
		
		// 最近的收盘价
		closePrice = closePriceIndicator.getValue(endIndex);
		// 最近的最高价
		maxPrice = maxPriceIndicator.getValue(endIndex);
		// 最近的最低价
		minPrice = minPriceIndicator.getValue(endIndex);

		smaShortValue = smaShortIndicator.getValue(endIndex);
		smaMiddleValue = smaMiddleIndicator.getValue(endIndex);

		macdDiff = macdDiffIndicator.getValue(endIndex);
		macdDea = macdDeaIndicator.getValue(endIndex);
		macd = macdDiff.minus(macdDea).multipliedBy(PrecisionNum.valueOf(2.0));
		
		daySMAInfo = DayKLineService.calculate(code, 55);
		
		hv = hvi.getValue(endIndex);
		lv = lvi.getValue(endIndex);
	}
	
	protected void showInfo() {
		System.out.println("现价为:" + closePrice.floatValue());
		System.out.println("最高价为:" + maxPrice.floatValue());
		System.out.println("最低价为:" + minPrice.floatValue());
		System.out.println("60分钟 " + shortNum + "日均线价格为:" + smaShortValue.floatValue());
		System.out.println("60分钟 " + middleNum + "日均线价格为:" + smaMiddleValue.floatValue());
		System.out.println("60分钟 " + shortNum + "日斜率为:" + slopeShort.floatValue());
		System.out.println("60分钟 " + middleNum + "日斜率为:" + slopeMiddle.floatValue());
		System.out.println("60分钟 macd diff为:" + macdDiff.floatValue());
		System.out.println("60分钟 macd dea为:" + macdDea.floatValue());
		System.out.println("60分钟 macd为:" + macd.floatValue());
		System.out.println("60分钟 " + GlobalConfig.ALARM_60MIN_MAXMIN_BAR_CNT + "周期最高价为：" + hv.floatValue());
		System.out.println("60分钟 " + GlobalConfig.ALARM_60MIN_MAXMIN_BAR_CNT + "周期最低价为：" + lv.floatValue());
		System.out.println("日线55日均线为:" + daySMAInfo.getSmaValue().floatValue());
		System.out.println("日线macd diff为：" + daySMAInfo.getMacdDiff().floatValue());
		System.out.println("日线macd dea为：" + daySMAInfo.getMacdDea().floatValue());
		System.out.println("日线macd value为：" + daySMAInfo.getMacdValue().floatValue());
	}
	
	// 做多条件判断
	protected String buyCondition() {
		score = 0;
		String msg = "方向：" + HTMLTool.red("多");
		msg = HTMLTool.appendNewLine(msg);
		
		if (slopeShort.isPositive() && slopeMiddle.isPositive()) {
			msg += "60分钟斜率都向上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_60MIN_SMA_SLOPE;
		} else {
			msg += "60分钟有斜率向下，" + HTMLTool.green("不利做多");
		}

		msg = HTMLTool.appendNewLine(msg);
		
		if (closePrice.isGreaterThan(smaShortValue) 
				&& closePrice.isGreaterThan(smaMiddleValue)) {
			msg += String.format("现价大于60分钟的%d日和%d日均线，", shortNum, middleNum) + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_60MIN_CLOSE_SMA_RELA;
		} else {
			msg += String.format("现价小于60分钟的%d日或%d日均线，", shortNum, middleNum) + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (macd.isPositive()) {
			msg += "60分钟macd在0轴以上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_60MIN_CLOSE_SMA_RELA;
		} else {
			msg += "60分钟macd在0轴以下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (closePrice.isGreaterThan(daySMAInfo.getSmaValue())) {
			msg += "现价在日线55日均线之上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_CLOSE_55SMA_RELA;
		} else {
			msg += "现价在日线55日均线之下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += checkSMA55Info();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getSlope55().isPositive()) {
			msg += "日线55日均线斜率向上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_55SMA_SLOPE;
		} else {
			msg += "日线55日均线斜率向下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd value：" + daySMAInfo.getMacdValue().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdValue().isPositive()) {
			msg += "日线macd value在0轴以上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_MACD_VALUE;
		} else {
			msg += "日线macd value在0轴以下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd diff：" + daySMAInfo.getDiff().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDiff().isPositive()) {
			msg += "日线macd diff在0轴以上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_MACD_DIFF;
		} else {
			msg += "日线macd diff在0轴以下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd dea：" + daySMAInfo.getMacdDea().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDea().isPositive()) {
			msg += "日线macd dea在0轴以上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_MACD_DEA;
		} else {
			msg += "日线macd dea在0轴以下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDiff().isGreaterThan(daySMAInfo.getMacdDea())) {
			msg += "日线macd diff在日线macd dea上，" + HTMLTool.red("有利做多");
			score += GlobalConfig.SCORE_DAY_MACD_DIFF_DEA_RELA;
		} else {
			msg += "日线macd diff在日线macd dea下，" + HTMLTool.green("不利做多");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += getTotalScoreMsg();
		
		msg = HTMLTool.appendNewLine(msg);
		
		return msg;
	}
	
	// 做空条件判断
	protected String sellCondition() {
		score = 0;
		String msg = "方向：" + HTMLTool.green("空");
		msg = HTMLTool.appendNewLine(msg);
		
		if (slopeShort.isNegative() && slopeMiddle.isNegative()) {
			msg += "60分钟斜率都向下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_60MIN_SMA_SLOPE;
		} else {
			msg += "60分钟斜率不都向下，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (closePrice.isLessThan(smaShortValue) 
				&& closePrice.isLessThan(smaMiddleValue)) {
			msg += String.format("现价小于60分钟%d日和%d日均线，", shortNum, middleNum) + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_60MIN_CLOSE_SMA_RELA;
		} else {
			msg += String.format("现价大于60分钟的%d日或%d日均线，", shortNum, middleNum) + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (macd.isNegative()) {
			msg += "macd在0轴以下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_60MIN_MACD_VALUE;
		} else {
			msg += "macd在0轴以上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (closePrice.isLessThan(daySMAInfo.getSmaValue())) {
			msg += "现价在日线的55日均线之下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_CLOSE_55SMA_RELA;
		} else {
			msg += "现价在日线的55日均线之上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += checkSMA55Info();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getSlope55().isNegative()) {
			msg += "日线55日均线斜率向下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_55SMA_SLOPE;
		} else {
			msg += "日线55日均线斜率向上，" + HTMLTool.red("不利做空");
		}

		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd value：" + daySMAInfo.getMacdValue().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdValue().isNegative()) {
			msg += "日线macd value在0轴以下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_MACD_VALUE;
		} else {
			msg += "日线macd value在0轴以上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd diff：" + daySMAInfo.getDiff().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDiff().isNegative()) {
			msg += "日线macd diff在0轴以下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_MACD_DIFF;
		} else {
			msg += "日线macd diff在0轴以上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += "日线macd dea：" + daySMAInfo.getMacdDea().floatValue();
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDea().isNegative()) {
			msg += "日线macd dea在0轴以下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_MACD_DEA;
		} else {
			msg += "日线macd dea在0轴以上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		if (daySMAInfo.getMacdDiff().isLessThan(daySMAInfo.getMacdDea())) {
			msg += "日线macd diff在日线macd dea下，" + HTMLTool.green("有利做空");
			score += GlobalConfig.SCORE_DAY_MACD_DIFF_DEA_RELA;
		} else {
			msg += "日线macd diff在日线macd dea上，" + HTMLTool.red("不利做空");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		
		msg += getTotalScoreMsg();
		
		msg = HTMLTool.appendNewLine(msg);
		
		return msg;
	}
	
	protected String getTotalScoreMsg() {
		String msg = "综合得分为：" + score + ",";
		
		if (score >= 90) {
			return HTMLTool.green(msg + "非常好，马上建仓");
		} else if (score >= 80) {
			return HTMLTool.yellow(msg + "还可以，建议观察一下再建仓");
		} else if (score >= 70) {
			return HTMLTool.yellow(msg + "建议观察一段时间，不要马上减建仓");
		} else {
			return HTMLTool.red(msg + "不建议建仓");
		}
	}
	
	protected String checkSMA55Info() {
		String msg = "现价与55日均线的价格差为：" + daySMAInfo.getDiff().floatValue();
		msg = HTMLTool.appendNewLine(msg);
		msg += "偏离度为："  + daySMAInfo.getPianlidu().floatValue();
		
		float pld1, pld2, pld3;
		
		if (curCode.startsWith("sh") || curCode.startsWith("sz")) {
			pld1 = 0.05f;
			pld2 = 0.1f;
			pld3 = 0.2f;
		} else {
			pld1 = 0.01f;
			pld2 = 0.02f;
			pld3 = 0.03f;
		}
		
		if (daySMAInfo.getPianlidu().isLessThanOrEqual(PrecisionNum.valueOf(pld1))) {
			msg += " " + HTMLTool.green("非常适合下单");
			score += GlobalConfig.SCORE_DAY_PLD_LEVEL1;
		} else if (daySMAInfo.getPianlidu().isLessThanOrEqual(PrecisionNum.valueOf(pld2))) {
			msg += " " + HTMLTool.yellow("比较适合下单");
			score += GlobalConfig.SCORE_DAY_PLD_LEVEL2;
		} else if (daySMAInfo.getPianlidu().isLessThanOrEqual(PrecisionNum.valueOf(pld3))) {
			msg += " " + HTMLTool.yellow("勉强适合下单");
		} else {
			msg += " " + HTMLTool.blue("最好不要下单");
		}
		
		msg = HTMLTool.appendNewLine(msg);
		msg += "日线55日均线斜率为：" + daySMAInfo.getSlope55().floatValue();
		
		return msg;
	}
	
	protected String appendChartInfo(String msg) {
		msg = HTMLTool.appendNewLine(msg);
		String minImgSrc, dailyImgSrc;
		
		if (curCode.startsWith("sh") || curCode.startsWith("sz")) {			
			minImgSrc = "http://image.sinajs.cn/newchart/min/n/" + curCode + ".gif";
			dailyImgSrc = "http://image.sinajs.cn/newchart/daily/n/" + curCode + ".gif";
		} else {
			String code = curCode;
			if (curCode.startsWith("JO")) {
				code = GlobalConfig.cngold2Sina.get(curCode);
			}
			minImgSrc = "http://image.sinajs.cn/newchart/v5/futures/mins/" + code + ".gif";
			dailyImgSrc = "http://image.sinajs.cn/newchart/v5/futures/daily/" + code +".gif";
		}
		
		msg += "<img src=\"" + minImgSrc + "\">";
		msg = HTMLTool.appendNewLine(msg);
		msg += "<img src=\"" + dailyImgSrc + "\">";
		return msg;
	}

	public void run() {
		try {
			// 初始化k线数据
			for (String code : codeList) {
				System.out.println("time:" + DateUtil.now());
				System.out.println("code:" + code);
				
				curCode = code;
				
				String nice = GlobalConfig.code2Nice.get(code);
				if (nice != null) {
					System.out.println("品种:" + nice);
				}
				
				initKLines(code);
					
				initIndicators();	
					
				initValues(code);	
					
				showInfo();
				
				String newMsg = code;
				
				if (nice != null) {
					newMsg += " " + nice;
				}

				// 短周期下穿中周期，潜在做空点
				if (smaDownCrossIndicator.getValue(endIndex)) {
					String msg = new String(newMsg);
					msg += String.format(" 60分钟%d日下穿%d日", shortNum, middleNum);
					msg = HTMLTool.appendNewLine(msg);
					msg += sellCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有下穿");
				}
				
				// 短周期上穿中周期，潜在做多点
				if (smaUpCrossIndicator.getValue(endIndex)) {
					String msg = new String(newMsg);
					msg += String.format(" 60分钟%d日上穿%d日", shortNum, middleNum);
					msg = HTMLTool.appendNewLine(msg);
					msg += buyCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有上穿");
				}
				
				// 最高价越过短期内最高点，潜在做多点
				if (maxPrice.isGreaterThanOrEqual(hv)) {
					String msg = new String(newMsg);
					msg += " 60分钟现价向上突破";
					msg = HTMLTool.appendNewLine(msg);
					msg += "最高价为：" + maxPrice.floatValue() + " " + "突破价为：" + hv.floatValue();
					msg = HTMLTool.appendNewLine(msg);
					msg += buyCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有向上突破");
				}
				
				// 最低价越过短期内最低点，潜在做空点
				if (minPrice.isLessThanOrEqual(lv)) {
					String msg = new String(newMsg);
					msg += " 60分钟现价向下突破";
					msg = HTMLTool.appendNewLine(msg);
					msg += "最低价为：" + minPrice.floatValue() + " " + "突破价为：" + lv.floatValue();
					msg = HTMLTool.appendNewLine(msg);
					msg += sellCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有向下突破");
				}
				
				// MACD死叉，潜在做空点
				if (macdDownCrossIndicator.getValue(endIndex)) {
					String msg = new String(newMsg);
					msg += " 60分钟MACD死叉";
					msg = HTMLTool.appendNewLine(msg);
					msg += sellCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有死叉");
				}
				
				// MACD金叉，潜在做多点
				if (macdUpCrossIndicator.getValue(endIndex)) {
					String msg = new String(newMsg);
					msg += " 60分钟MACD金叉";
					msg = HTMLTool.appendNewLine(msg);
					msg += buyCondition();
					
					System.out.println(msg);
					
					if (score >= GlobalConfig.NOTI_SCORE) {
						// 添加图表元素
						msg = appendChartInfo(msg);
						// 发邮件
						MailTool.send("交易信号", msg);
					} else {
						System.out.println("分数不够");
					}
				} else {
					System.out.println("没有金叉");
				}
		
			}
		} catch (Exception e) {
			e.printStackTrace();
			// 发邮件
			MailTool.send("交易信号程序异常", ExceptionUtil.stacktraceToString(e));
		}
	}

}
